package com.smsp.service.impl;

import com.smsp.common.ServerResponse;
import com.smsp.dao.MessageDetailMapper;
import com.smsp.dao.MessageWay;
import com.smsp.dao.impl.MessageWayImpl;
import com.smsp.entity.MessageDetail;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.lang.System.*;

@Service("Autoquery")
@Transactional
public class queryReceiveTime {
    public Logger logger = LoggerFactory.getLogger(queryReceiveTime.class);
    @Autowired
    private MessageDetailMapper messageDetailMapper;
    public void queryreceivetime(){
        List<MessageDetail> resultlist = messageDetailMapper.selectAll();
        for(int i = 0 ;i< resultlist.size();i++){
            if(resultlist.get(i).getReceiveTime()==null){
                MessageWay messageWay = new MessageWayImpl();
                ServerResponse serverResponse=messageWay.queryMessageDetail(resultlist.get(i).getMessageDetailExtend1());
                List<String> resList = java.util.Arrays.asList(serverResponse.getData().toString().split(","));
                SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                try{
                    Date receiveTime=format.parse(resList.get(0).replaceAll("[ ]",""));
                    resultlist.get(i).setReceiveTime(receiveTime);
                }catch (ParseException e){
                    e.printStackTrace();
                }
            }
        }
    }
}
